package org.jackysoft.controller;

import java.util.Collection;

import javax.annotation.Resource;

import org.jackysoft.annotations.Logger;
import org.jackysoft.controller.base.AbstractController;
import org.jackysoft.entity.TreeNode;
import org.jackysoft.entity.WebModule;
import org.jackysoft.service.TreeNodeService;
import org.jackysoft.service.WebModuleService;
import org.jackysoft.util.OperationType;
import org.jackysoft.ztree.TreeNodeZtreeFunction;
import org.jackysoft.ztree.ZTreeNode;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.google.common.base.Function;
import com.google.common.collect.Collections2;



@Logger(label = "资源URL", logType = OperationType.System)
@Controller
@RequestMapping("/treenode")
public class TreeNodeController extends AbstractController<TreeNode> {

	@Resource
	private TreeNodeService service;
	@Resource
	private WebModuleService moduleService;
	
	@RequestMapping("/start")
	public void start( @ModelAttribute Collection<WebModule> webModules) {
		webModules = moduleService.findAll();		
	}
	
	@RequestMapping("/listall")
	public void listall(@ModelAttribute Collection<ZTreeNode> zbeans,String parent) throws Exception {
		zbeans = Collections2.transform(service.getsByParent(parent),
				new TreeNodeZtreeFunction(false));
		
	}

	@RequestMapping("/allbyacegi")
	public void allbyacegi(@ModelAttribute Collection<String> idList,String secRole) throws Exception {
		idList = Collections2.transform(service.getsBySecurityRole(secRole),
				new Function<TreeNode, String>() {

					@Override
					public String apply(TreeNode from) {
						return from.getId();
					}

				});

		
	}	
}
